$(function () {
    let navId = localStorage.getItem("navId");
    findNavById(navId)
});

//通过id查找
function findNavById(id) {
    $.ajax({
        url: '/back/nav/findByNavId',
        data: {id: id},
        type: 'get',
        dataType: 'json',
        success: function (data) {
            setNavData(data.navModel);
        }
    })
}

function setNavData(data) {
    $("#navId").val(data.id);
    $("#name").val(data.name);
    $("#href").val(data.href);
}

function cancelEdit() {
    $("#right").load('/back/nav/navManage.html')
}

function navEdit() {
    var data = {
        id:$("#navId").val(),
        name: $("#name").val(),
        href: $("#href").val()
    };
    $.ajax({
        url:'/back/nav/navEdit',
        data:data,
        type:'post',
        dataType: 'json',
        success:function (data) {
            if (data.count===1){
                alert("修改成功！")
                $("#right").load('/back/nav/navManage.html')
            }else{
                alert("修改失败")
            }
        }
    })
}
